package com.zb.controller;


import com.zb.entity.dto.ModuleDto;
import com.zb.entity.dto.ModuleSelectDto;
import com.zb.result.Result;
import com.zb.service.ZjAdmModuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 后台模块表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-07-12
 */
@Api(tags = "模块类接口")
@RestController
@RequestMapping("/module")
public class ZjAdmModuleController {
    @Autowired
    private ZjAdmModuleService admModuleService;

    @ApiOperation("新增或修改模块")
    @PostMapping("/save")
    public Result save(@RequestBody ModuleDto moduleDto) {
        admModuleService.save(moduleDto);
        return Result.success();
    }

    @ApiOperation("功能模块列表查询")
    @PostMapping("/getList")
    public Result getList(@RequestBody ModuleSelectDto selectDto) {
        return Result.success().data(admModuleService.getList(selectDto));
    }

    @ApiOperation("批量禁用或启用功能模块")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "是否禁用：false-否，true-是", required = true) boolean disable,
                          @RequestBody @ApiParam(value = "功能模块ID集合", required = true) List<Long> idList) {
        admModuleService.updateBatchDisableById(idList, disable);
        return Result.success(disable? "禁用功能模块成功" : "启用功能模块成功");
    }

}
